The present invention relates to a time measurement technique using a timer in a device performing a computer process. More specifically, the present invention relates to a time measurement device, a micro-controller, and a method of measuring a time capable of performing a time measurement operation with high accuracy at a low cost especially at a high speed operation.
In general, as a device performing a computer process, a conventional micro-controller has been known, in which an entire computer system is integrated on one single semiconductor chip. The conventional micro-controller may be provided with a plurality of oscillators constituting an operation clock. Accordingly, it is possible to switch the operation clock for a CPU (Central Processing Unit) or a peripheral circuit of a timer according to a usage or a purpose of the computer process.
For example, in the conventional micro-controller, a low speed clock is selected as the operation clock in a normal operation for conserving power consumption. When it is necessary to operate at a high speed, the operation clock is switched to a high speed clock.
As an example, in a conventional system for performing wireless communication, it is configured that until reception of a command through wireless transmission is started, the conventional system is operated with a low speed clock to become an idle state for waiting for the command. Accordingly, it is possible to reduce power consumption during the idle state for waiting for the command.
It is supposed that the conventional system for performing the wireless communication may include a first device and a second device. The first device may be configured such that a state thereof is continuously changed in a specific interval, and the state of the first device is transmitted through the wireless transmission. The second device may be configured to receive the state of the first device so that the second device changes an operation thereof in the same interval according to the state of the first device. With such a configuration, even when the wireless transmission from the first device is interrupted due to interference, it is possible to continuously perform the operation of the second device according to the interval received previously.
In the conventional system for performing the wireless communication described above, in order for the second device to synchronize with the first device even when the wireless transmission from the first device is interrupted, it is necessary to accurately measure the time interval of the command thus received. Accordingly, it is necessary to provide a timer with high accuracy for measuring the time interval of the command.
In general, the timer disposed in the conventional micro-controller includes the oscillator such as a crystal oscillator and an RC oscillator. The crystal oscillator is provided with a crystal oscillation element as an external part, and is capable of generating a clock with high accuracy.
In the RC oscillator, it is not necessary to provide the external part to the conventional micro-controller, and it is possible to integrate inside the conventional micro-controller. Accordingly, it is possible to produce the RC oscillator at a relatively low cost as compared with the crystal oscillator. However, in the RC oscillator, it is difficult to generate a clock with high accuracy as compared with the crystal oscillator. Accordingly, it is difficult to apply the RC oscillator to an application in which it is necessary to measure the time accurately.
In order to solve the problem described above, Patent Reference 1 has disclosed such a conventional technique capable of measuring the time accurately even when the timer is formed of the RC oscillator. FIG. 15 is a time chart showing an operation of the conventional micro-controller disclosed in Patent Reference 1.    Patent Reference 1: Japanese Patent Publication No. 10-49251
In the conventional micro-controller disclosed in Patent Reference 1, the RC oscillator and the crystal oscillator are configured to generate reference clocks. Further, an interruption request register is provided for generating an interruption request signal.
As shown in FIG. 15, the interruption request signal of the interruption request register is raised at a rise of the reference clock of the RC oscillator. From the rise of the interruption request signal, it is configured to detect a start of one cycle of the reference clock (indicated with “A” in FIG. 15) of the RC oscillator and an end of one cycle of the reference clock (indicated with “B” in FIG. 15) of the RC oscillator. During the one cycle of the reference clock of the RC oscillator, a count value (a measurement value) of the reference clock of the crystal oscillator that possesses high accuracy and a high frequency is measured.
As described above, with the crystal oscillator that possesses high accuracy and a high frequency, one cycle of the reference clock of the RC oscillator is measured, so that the actual cycle of the RC oscillator can be accurately measured. In the next step, it is configured to calculate a ratio of the actual cycle thus measured to a cycle (an expected measurement value) of the RC oscillator in a normal operation, so that a compensation coefficient is determined according to the ratio thus calculated. At last, the compensation coefficient is multiplied by the measurement value of the timer to which the RC oscillator is input.
In the conventional micro-controller disclosed in Patent Reference 1, however, there are the following problems.
As for the first problem, in the conventional technique disclosed in Patent Reference 1, it is necessary to provide the crystal oscillator capable of directly measuring the clock cycle of the RC oscillator. The crystal oscillator with a high frequency tends to be expensive. Accordingly, even though the RC oscillator is used, it is difficult to reduce a cost.
In general, when the crystal oscillator has a higher frequency, the cost thereof tends to increase. Accordingly, when a computer system is provided with the crystal oscillator with a high frequency for controlling a time, the cost of the computer system is increased as well.
In order for the conventional micro-controller to operate at a high speed and a low cost, it is desirable to increase the clock of the RC oscillator as the system clock. However, in this case, according to the conventional technique disclosed in Patent Reference 1, it is necessary to provide the crystal oscillator with the high frequency.
It is noted that in the conventional micro-controller disclosed in Patent Reference 1, the clock of the crystal oscillator is used as the system clock for the high speed operation. However, in order for the conventional micro-controller to operate at a higher speed, it is necessary to provide the crystal oscillator with the higher frequency, thereby increasing the cost.
As for the second problem, in the conventional technique disclosed in Patent Reference 1, in order to determine the compensation coefficient accurately, the RC oscillator must have a frequency lower than that of the crystal oscillator. Accordingly, it is difficult to increase a resolution of the timer to which the reference clock of the RC oscillator with a low frequency is input.
In order to increase the resolution of the timer, it is necessary to use the RC oscillator capable of oscillating the reference clock at a high frequency. It is possible to increase the frequency of the RC oscillator at a relatively low cost. However, in the conventional micro-controller disclosed in Patent Reference 1, in order to increase the resolution of the timer, it is necessary to provide the crystal oscillator with the higher frequency, thereby increasing the cost.
It should be noted that as Patent Reference 1 has disclosed, when the frequency of the RC oscillator is divided, it is possible to increase the resolution of the timer with the crystal oscillator having a low frequency. However, in this case, it is necessary to provide a frequency dividing unit. Patent Reference 2 has disclosed such a frequency dividing unit.    Patent Reference 2: Japanese Patent Publication No. 05-48433
When the frequency dividing unit is provided, one cycle of the reference clock of the RC oscillator is divided and extended. Accordingly, when the compensation coefficient is determined, it takes a long time to measure the clock of the crystal oscillator generated during one cycle of the reference clock of the RC oscillator.
As for the third problem, in the conventional technique disclosed in Patent Reference 1, when the compensation coefficient is determined, the start point and the end point of the clock of the crystal oscillator are detected through polling. Further, the compensation coefficient is used for outputting through a port through the polling. Accordingly, in the conventional micro-controller disclosed in Patent Reference 1, the CPU is operated all the time, so that it is difficult to switch the CPU to a power save mode. Further, during the polling, it is difficult for the CPU to perform other process.
As for the fourth problem, in the conventional technique disclosed in Patent Reference 1, when the compensation coefficient is determined, one cycle of the reference clock of the RC oscillator with the low frequency is measured by the timer to which the clock of the crystal oscillator with the high frequency. Accordingly, when a difference in the speeds between the RC oscillator and the crystal oscillator is increased, the measurement value of the timer tends to be overflowed.
Patent References 3 and 4 have disclosed a conventional technique for controlling the measurement operation of the clock of the oscillator by the timer.    Patent Reference 3: Japanese Patent Publication No. 2006-309479    Patent Reference 4: Japanese Patent Publication No. 08-139593
In the conventional technique disclosed in Patent Reference 3, in order to compensate an error in a frequency of a first clock signal, a second clock signal having a lower frequency than that of the first clock signal is input. In the next step, a pulse number of the first clock signal contained in one cycle of the second clock signal is measured with a pulse number counter.
In the next step, a calculation unit calculates compensation information using the pulse number measured with the pulse number counter and a reference pulse number determined in advance. In the next step, a compensation signal output unit outputs a clock compensation signal according to the compensation information calculated with the calculation unit. At last, an output of the first clock signal is compensated at an output gate according to the clock compensation signal output from the compensation signal output unit.
In the conventional technique disclosed in Patent Reference 3, however, the first clock signal generated with the RC oscillator and to be input into the timer is partially cut-off according to one cycle of the second clock signal generated with the crystal oscillator, so that a part of the first clock signal is not transmitted to the timer. Accordingly, it is necessary to modify the timer, thereby increasing the number of components in the configuration.
In the conventional technique disclosed in Patent Reference 4, the frequency of the RC oscillator is measured per one cycle of the reference oscillator. When the measurement value exceeds a specific value, the number of switch transistors is increased, so that the total capacity of the RC oscillator is increased and the output oscillation frequency is decreased. When the measurement value is below a specific value, the number of the switch transistors is decreased, so that the total capacity of the RC oscillator is decreased and the output oscillation frequency is increased.
In the conventional technique disclosed in Patent Reference 4, the process described above is repeated, so that the oscillation frequency is automatically controlled and stabilized at a target value with a separate internal reference oscillator. However, similar to the conventional technique disclosed in Patent Reference 3, it is necessary to increase the number of the switch transistors to modify the clock, thereby increasing the number of the components in the configuration.
In view of the problems described above, an object of the present invention is to provide a time measurement device, a micro-controller, and a method of measuring a time. In the present invention, it is possible to perform a time measurement operation with high accuracy and a low cost especially when a high speed operation is performed with a timer disposed in a computer device.
Further objects and advantages of the invention will be apparent from the following description of the invention.